package com.hmys.api.controller;

import com.github.pagehelper.PageInfo;
import com.hmys.api.model.WebCity;
import com.hmys.api.model.WebState;
import com.hmys.api.response.Result;
import com.hmys.api.response.ResultCode;
import com.hmys.api.response.ResultPage;
import com.hmys.api.service.WebStateService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by chen365 on 2018/04/09.
 */
@RestController
@Api(tags = "州")
@RequestMapping(value = "/state")
public class StateController {
    @Autowired
    private WebStateService webStateService;

    @ApiOperation(value = "列表", notes = "列表", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiImplicitParams({
            @ApiImplicitParam(dataType = "int", name = "pageIndex", value = "页码", required = true, paramType = "path"),
            @ApiImplicitParam(dataType = "int", name = "pageSize", value = "每页数", required = true, paramType = "path")
    })
    @GetMapping(value = "/list/{pageIndex}/{pageSize}")
    public Object list(@PathVariable("pageIndex") Integer pageIndex,
                       @PathVariable("pageSize") Integer pageSize) {
        WebState record = new WebState();
        record.setStatus(true);
        PageInfo<WebState> pageInfo = webStateService.selectByBean(pageIndex, pageSize, record);
        if (pageInfo.getList().size() > 0) {
            return new ResultPage(ResultCode.SUCCESS, pageInfo);
        } else {
            return new Result<>(ResultCode.NOT_FOUND);
        }
    }
}
